package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ResourceController
 * @Author xxxx
 * @Date 2024-10-23
 */

/**
 * 资源前段控制器
 */
@Slf4j
@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    /**
     * 资源列表查询
     * @param resourceDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("资源列表")
    @ApiImplicitParam(name = "resourceDto",value = "资源DTO对象",required = true,dataType = "ResourceDto")
    @ApiOperationSupport(includeParameters = {"resourceDto.parentResourceNo","resourceDto.resourceType"})
    public ResponseResult<List<ResourceVo>> resourceList(@RequestBody ResourceDto resourceDto){
        log.info("资源列表，请求参数：{}",resourceDto);
        //调用业务获取资源列表数据
        List<ResourceVo> resourceVoList = resourceService.resourceList(resourceDto);
        //返回
        return ResponseResult.success(resourceVoList);
    }

    /**
     * 资源对象
     * @param resourceDto
     * @return
     */
    @PostMapping("/tree")
    @ApiOperation("资源树形")
    @ApiImplicitParam(name = "resourceDto",value = "资源DTO对象",required = true,dataType = "ResourceDto")
    @ApiOperationSupport(includeParameters = {"resourceDto.label"})
    public ResponseResult<List<ResourceVo>> resourceTreeVo(@RequestBody ResourceDto resourceDto){
        log.info("资源树形，请求参数：{}",resourceDto);
        //调用业务获取树形菜单对象
        TreeVo treeVo = resourceService.resourceTreeVo(resourceDto);
        //返回
        return ResponseResult.success(treeVo);
    }

    /**
     * 资料添加
     * @param resourceDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "资源添加", notes = "资源添加")
    @ApiImplicitParam(name = "resourceDto", value = "资源DTO对象", required = true, dataType = "ResourceDto")
    @ApiOperationSupport(includeParameters = {"resourceDto.dataState"
            , "resourceDto.icon"
            , "resourceDto.parentResourceNo"
            , "resourceDto.requestPath"
            , "resourceDto.resourceName"
            , "resourceDto.resourceType"
            , "resourceDto.sortNo"})
    public ResponseResult createResource(@RequestBody ResourceDto resourceDto) {

        log.info("资料添加，请求参数：{}",resourceDto);

        //调用进行资源添加
        Boolean flag = resourceService.createResource(resourceDto);
        return ResponseResult.success(flag);
    }
}
